<template>
	<view class="change_password">
		<app-title :title='`修改${title}密码`'></app-title>
		<view class="change_password_box">
			<view class="change_password_box_item">
				<view class="change_password_box_item_" style="width: 30%;">
					{{type === 0?'原':''}}登录密码
				</view>
				<view class="change_password_box_item_" style="flex: 1;">
					<input v-model="formerPassword" type="text" :password='isformerPassword'
						:placeholder="`请输入原登录密码`" />



					<!-- <input v-model="formerPassword" v-else type="number" :password='isformerPassword' maxlength="6"
						:placeholder="`请输入登录密码`" /> -->
				</view>
				<uni-icons :type="isformerPassword?'eye-filled':'eye'"
					@click="isformerPassword = !isformerPassword"></uni-icons>
			</view>
			<view class="change_password_box_item"
				style="border-top:1rpx solid #f6f6f6;border-bottom:1rpx solid #f6f6f6;">
				<view class="change_password_box_item_" style="width: 30%;">
					新{{title}}密码
				</view>
				<view class="change_password_box_item_" style="flex: 1;">
					<input v-model="newPassword" v-if="type === 0" type="text" :password='isnewPassword'
						:placeholder="`请输入新登录密码`" />
					<input v-model="newPassword" v-else type="number" :password='isnewPassword' maxlength="6"
						:placeholder="`请输入新${title}密码`" />
				</view>
				<uni-icons :type="isnewPassword?'eye-filled':'eye'" @click="isnewPassword = !isnewPassword"></uni-icons>
			</view>
			<view class="change_password_box_item">
				<view class="change_password_box_item_" style="width: 30%;">
					确认新密码
				</view>
				<view class="change_password_box_item_" style="flex: 1;">
					<input v-model="verifyPassword" :password='isverifyPassword' v-if="type === 0" type="text"
						:placeholder="`请确认新登录密码`" />
					<input v-model="verifyPassword" :password='isverifyPassword' v-else type="number" maxlength="6"
						:placeholder="`请确认新${title}密码`" />
				</view>
				<uni-icons :type="isverifyPassword?'eye-filled':'eye'"
					@click="isverifyPassword = !isverifyPassword"></uni-icons>
			</view>
		</view>
		<view class="change_password_message">如果忘记原{{title}}密码，请联系管理员修改</view>

		<view class="change_password_button">
			<view class="change_password_button_box" @click="modificationFun">修改密码</view>
		</view>
	</view>
</template>

<script>
	import {
		values
	} from 'lodash';
	import {
		member_bind,
		member_bind_paypasschange,
		api_index_user_info
	} from '@/api/member.js'
	export default {
		data() {
			return {
				isformerPassword: true,
				isnewPassword: true,
				isverifyPassword: true,
				title: '',
				type: 0,
				formerPassword: '',
				newPassword: '',
				verifyPassword: '',
				openid: '',
				isSettingsPassword: 0
			}
		},
		onLoad(e) {
			this.type = e.type * 1
			this.title = this.type === 0 ? '登录' : '交易';

			uni.setNavigationBarTitle({
				title: `修改${this.title}密码`
			});
			uni.getStorage({
				key: 'openid',
				success: (res) => {
					this.openid = res.data;
					this.api_index_user_infoFun();
				},
				fail: () => {
					uni.reLaunch({
						url: '/pages/login/login'
					});
				}
			});


		},
		methods: {
			async api_index_user_infoFun() {
				if (this.type === 0) {
					return
				}
				let data = await api_index_user_info(this.openid);
				console.log(data);
				if (data.paypass === '未设置') {
					this.isSettingsPassword = 1
				}
			},
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			//提示
			showinteraction(title, icon = 'none') {
				uni.showToast({
					title,
					icon,
					duration: 2000,
					mask: false
				})
			},
			async modificationFun() {
				let up = {}
				if (this.type === 0) {
					up = {
						pwd: this.formerPassword,
						new_pwd: this.newPassword,
						confirm: this.verifyPassword,
						openid: this.openid
					}
					let data = await member_bind(up);
					console.log(data);
					if (data.status === 1) {
						setTimeout(() => {
							uni.clearStorage();
							uni.reLaunch({
								url: '/pages/login/login'
							})
						}, 1000)
					}


				} else {
					up = {
						openid: this.openid,
						paypass: this.newPassword,
						confirm: this.verifyPassword,
						loginpass: this.formerPassword
					}
					let data = await member_bind_paypasschange(up);
					console.log(data);
				}
			}
		}
	}
</script>

<style lang="scss">
	.change_password {
		width: 100%;

		.change_password_box {
			margin-top: 20rpx;
			width: 100%;
			padding: 0 20rpx;
			background-color: #fff;

			.change_password_box_item {
				width: 100%;
				padding: 30rpx 24rpx;
				font-size: 28rpx;
				color: #666;
				display: flex;

				input {
					width: 100%;
					font-size: 28rpx;
				}
			}
		}

		.change_password_message {
			width: 100%;
			padding: 50rpx 0px 30rpx;
			text-align: center;
			font-size: 30rpx;
			color: red;


		}

		.change_password_button {
			padding: 0 40rpx;

			.change_password_button_box {
				width: 100%;
				height: 80rpx;
				text-align: center;
				line-height: 80rpx;
				border-radius: 100rpx;
				background: linear-gradient(3deg, #ff3232, #ff3232, #ff8719);
				color: #fff;
			}
		}
	}
</style>